﻿@using SmartCode
@using SmartCode.Db
@model BuildContext
@{
    Layout = "_SqlMapLayout.cshtml";
    var project = Model.Project;
    var dbSource = Model.GetDataSource<DbSource>();
    var buildTask = Model.Build;
    var table = Model.GetCurrentTable();
    var pkCol = table.PKColumn;
    if (pkCol == null)
    {
        throw new SmartCodeException($"{table.Name} can not find PKColumn！");
    }
    var primaryKeyType = pkCol?.LanguageType ?? "int";
    var autoIncrement = table.AutoIncrement;
    var dbPrefix = dbSource.DbProvider.ParameterPrefix;
    var notEqCols = table.Columns.Where(m => m.ConvertedName != m.Name);
    var resultMapName = $"{table.ConvertedName}ResultMap";
    var queryStatementResultMap = table.HasColNameNotEqConvertedName ? $"ResultMap=\"{resultMapName}\"" : "";
}
@section QueryByPage
    {
    <!--获取分页数据-->
    <Statement Id="QueryByPage" @(queryStatementResultMap)>
        Select 
        <Include RefId="AllCols"/>
        From @table.Name As T
        <Include RefId="QueryParams" />
        <Switch Prepend="Order By" Property="OrderBy">
            <Default>
                T.@pkCol.Name Desc
            </Default>
        </Switch>
        Limit @(dbPrefix)Offset,@(dbPrefix)PageSize
    </Statement>
}

